package com.runa.rccprotocol.analysis.En13757;


import com.runa.rccprotocol.analysis.En13757.decoder.DIF;
import com.runa.rccprotocol.analysis.En13757.decoder.VIF;

import java.text.NumberFormat;

/**
 * @author diandian
 * @Date 2021/11/8 21:15
 */
public class UnitData {
    private DIF dif;

    private VIF vif;

    //数据序号
    private Integer number;

    //数据值
    private Object value;


    public UnitData(DIF dif, VIF vif, Integer number, Object value) {
        this.dif = dif;
        this.vif = vif;
        this.number = number;
        this.value = value;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public DIF getDif() {
        return dif;
    }

    public void setDif(DIF dif) {
        this.dif = dif;
    }

    public VIF getVif() {
        return vif;
    }

    public void setVif(VIF vif) {
        this.vif = vif;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    @Override
    public String toString() {
        NumberFormat format = NumberFormat.getInstance();
//        format.setGroupingUsed(false);// 是否以逗号隔开, 默认true以逗号隔开,如[123,456,789.128]
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"dif\":")
                .append(dif);
        sb.append(",\"vif\":")
                .append(vif);
        sb.append(",\"number\":")
                .append(number);
        sb.append(",\"value\":")
                .append(value instanceof Number ? format.format(value) : value);
        sb.append('}');
        return sb.toString();
    }
}